<template>
  <div class="BuildingnoList-box">
      <div class="title">
          <span>绑定楼房号列表</span>
      </div>
      <div class="index-middlebox">
          <div class="middle-item">
              <!-- <span>商品名称</span> -->
              <template>
                  <el-input class="productname-input" placeholder="业主名字/手机号/楼房号/物业管理公司名称" v-model="seachname" @change="getqueryPropertyUserList"></el-input>
              </template>
          </div>
      </div>
      <div class="index-list-box">  
        <template>
                <el-table :data="queryPropertyUserList"
                        border
                        style="width: 100%">>
                <el-table-column 
                                label="序号"
                                type="index"
                                 align="center">
                </el-table-column>
                <el-table-column prop="mobilePlone"
                                label="手机号"
                                 align="center">
                </el-table-column>
                <el-table-column prop="userName"
                                label="业主名字"
                                 align="center">
                </el-table-column>
                <el-table-column prop="userSite"
                                label="业主楼房号"
                                 align="center">
                </el-table-column>
                <el-table-column prop="propertyCompanyName"
                                label="物业管理公司名称"
                                 align="center">
                </el-table-column>
                <el-table-column prop='status'
                                label="状态"
                                 align="center">
                                <template slot-scope="scope">
                                  <span v-if="scope.row.status == 0">未审核</span>
                                  <span v-if="scope.row.status == 1">审核通过</span>
                                  <span v-if="scope.row.status == 2">审核不通过</span>
                                </template>
                </el-table-column>
                <el-table-column fixed="right"
                                label="操作"
                                width="350" align="center">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="handleaudit(scope.$index, scope.row, 1)" v-if="scope.row.status != 1 && scope.row.status != 2">审核通过</el-button>
                        <el-button size="mini" @click="handleaudit(scope.$index, scope.row, 2)" v-if="scope.row.status != 1 && scope.row.status != 2">审核不通过</el-button>
                        <el-button size="mini" @click="handlecompile(scope.$index, scope.row)">编辑</el-button>
                        <el-button size="mini" @click="getdeletePropertyUser(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
                </el-table>
            </template>
      </div>
      <!-- 分页器 -->
      <div class="current">
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-size="10"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
      <div>
        <el-dialog
                title="编辑信息"
                :visible.sync="dialogVisible"
                width="30%"
                >
                <div class="compile-box">
                  <div class="compile-item">
                    <span>手机号码:</span>
                    <el-input class="compile-input"  v-model="phone"></el-input>
                  </div>
                  <div class="compile-item">
                    <span>业主名字:</span>
                    <el-input class="compile-input"  v-model="name"></el-input>
                  </div>
                  <div class="compile-item">
                    <span>业主楼房号:</span>
                    <el-input class="compile-input"  v-model="Buildingno"></el-input>
                  </div>
                  <div class="compile-item">
                    <span>物业管理公司名称:</span>
                    <el-input class="compile-input"  v-model="propertyCompanyName"></el-input>
                  </div>
                </div>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="getupdatePropertyUser">确 定</el-button>
                </span>
        </el-dialog>
      </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { queryPropertyUserList, reviewPropertyUser, getupdatePropertyUser, getdeletePropertyUser} from "@/api/PropertyManagement";
export default {
// import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
        queryPropertyUserList:[],
        supplierid:'',
        value: '',
        date: '',
        total: 0, // 用户总条数
        pagesize: 10, //每页显示多少条，默认为10条
        pageNo: 1, // 当前页码，默认为第一页
        seachname:'',//搜索
        dialogVisible:false,
        phone:'',//手机号码
        name:'',//业主名字
        Buildingno:'',//楼房号
        propertyCompanyName:'',//物业管理名称
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getqueryPropertyUserList()
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
      getqueryPropertyUserList(){
        let data = {
          pageNo: this.pageNo,
          pagesize: this.pagesize,
          requestParam:this.seachname
        }
        queryPropertyUserList(data).then(res => {
          this.queryPropertyUserList = res.rows
          this.pageNo = res.pageNo
          this.pagesize = res.pageSize
          this.total = res.total
        })
      },
      handleSizeChange(val) {
        this.pagesize = val;
        this.getqueryPropertyUserList();
      },
      handleCurrentChange(val) {
        this.pageNo = val;
        this.getqueryPropertyUserList();
      },
      // 审核
      handleaudit(index, row, stash){
        let data = {
          userId: row.userId,
          status:stash
        }
        reviewPropertyUser(data).then(res => {
          this.getqueryPropertyUserList()
        })
      },
      // 编辑
      handlecompile(index, row){
        this.dialogVisible = true
        this.phone = row.mobilePlone
        this.name = row.userName
        this.Buildingno = row.userSite
        this.propertyCompanyName = row.propertyCompanyName
        this.userId = row.userId
        this.propertyCompanyId = row.propertyCompanyId
      },
      // 保存编辑
      getupdatePropertyUser(){
        let data = {
          userId:this.userId,
          mobilePlone:this.phone,
          userName:this.name,
          userSite:this.Buildingno,
          propertyCompanyId:this.propertyCompanyId,
          propertyCompanyName:this.propertyCompanyName
        }
        getupdatePropertyUser(data).then(res =>{
          if(res.code == 20000){
            this.dialogVisible = false
            this.$message('编辑成功')
            this.getqueryPropertyUserList()
          }
        })
      },
      // 删除楼房号
      getdeletePropertyUser(index , row){
        let data = {
          userId: row.userId
        }
        getdeletePropertyUser(data).then(res => {
          console.log('删除成功',res)
          if(res.code == 20000){
            this.$message('删除成功')
            this.getqueryPropertyUserList()
          }
        })
      }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
.BuildingnoList-box{
    width: 100%;
    .title{
        width: 100%;
        padding:20px 40px 20px 40px;
        box-sizing: border-box;
        span{
            font-size: 20px;
            font-weight: bold;
        }
    }
    .index-middlebox{
        width: 100%;
        padding-left: 40px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        box-sizing: border-box;
        .middle-item{
            span{
                display: inline-block;
                font-size: 14px;
                padding-right: 15px;
                padding-left: 30px;
                box-sizing: border-box;
            }
            .productname-input{
                width: 300px;
            }
            .search{
                width: 120px;
                margin-left:20px;
            }
            .search2{
                width: 120px;
                margin-left:20px;
            }
        }
    }
    .index-list-box{
        width: 100%;
        padding: 30px 40px;
        box-sizing: border-box;
    }
    .current {
      .block {
        text-align: center;
      }
    }
    .compile-box{
      width: 100%;
      text-align: center;
      .compile-item{
        width: 100%;
        margin-bottom: 20px;
      }
      .compile-input{
        width: 250px;
      }
    }
}
</style>
